<template>
	<view>
		<menuBox :menuInfo="menuInfoStu" v-if="isStu"></menuBox>
		<menuBox :menuInfo="menuInfo" v-else></menuBox>
	</view>
</template>

<script>
import menuBox from '@/wxcomponents/commonLayout/menu';
import { dictCode } from '@/libs/common.js';
import userMixins from '@/libs/userMixins.js';
export default {
	mixins: [userMixins],
	data() {
		return {
			isStu: '',
			menuInfo: {
				base: {
					tit: ['请假类型', '请假原因', '状态'],
					menuProp: ['leaveType', 'leaveReason', 'status']
				},
				list: []
			},
			menuInfoStu: {
				base: {
					tit: ['学生姓名', '申请时间', '状态'],
					menuProp: ['name', 'applyDate', 'status']
				},
				list: []
			}
		};
	},
	async onLoad() {
		await this.getList();
		let user = uni.getStorageSync('user');
		this.isStu = user.roles.includes(2)
	},
	methods: {
		async getList() {
			let self = this;
			let caseMap = [
				{
					condition() {
						// 学生
						return self.calMenuShow('学生身份')
					},
					async func() {
						let resp = await self.$http.post({
							url: '/stu/studentLeave/listApplyInfo'
						});
						let list = resp.result.records.map(item => {
							let obj = {
								url: './leaveRecord?data=' + JSON.stringify(item),
								leaveType: self.getDictNameWithCodeAndValue('dict_student_leave_type', item.leaveType),
								// leaveReason: self.getDictNameWithCodeAndValue('dict_student_reason', item.leaveReason),
								// status: self.getDictNameWithCodeAndValue('dict_student_leave_status', item.leaveStatus),
								name: item.studentName,
								applyDate: item.applyDate,
								status: self.getDictNameWithCodeAndValue('dict_student_leave_status', item.leaveStatus),

								data: item
							};
							return obj;
						});
						self.menuInfoStu.list = list;
					}
				},
				{
					condition() {
						// 教职工
						return !self.calMenuShow('学生身份')
					},
					async func() {
						let resp = await self.$http.post({
							url: '/oa/leaveApply/list'
						});
						let list = resp.result.map(item => {
							item.detailType = 'detail';
							let obj = {
								url: './teacherLeaveDetail?data=' + JSON.stringify(item),
								leaveType: self.getDictNameWithCodeAndValue('dict_leave_type', item.leaveType),
								leaveReason: self.getDictNameWithCodeAndValue('dict_leave_reason', item.leaveReason),
								status: self.getDictNameWithCodeAndValue('dict_student_leave_status', item.applyStatus),
								data: item
							};
							return obj;
						});
						self.menuInfo.list = list;
					}
				}
			];
			let findOne = caseMap.filter(item => {
				return item.condition();
			})[0];
			if (!findOne) {
				alert(`getList方法出错`);
			}
			findOne.func();
		}
	},
	components: {
		menuBox
	}
};
</script>

<style></style>
